package com.example.zyfypt_611cgt.model;

import com.example.zyfypt_611cgt.bean.ListSpecialBean;
import com.example.zyfypt_611cgt.common.Common;
import com.example.zyfypt_611cgt.iface.ListSpecialIface;
import com.example.zyfypt_611cgt.iface.ListSpecialListener;
import com.example.zyfypt_611cgt.service.ListSpecialService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class ListSpecialModel implements ListSpecialIface {
    private Retrofit retrofit;

    public ListSpecialModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl(Common.BASEURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    @Override
    public void getResultList(String mod, int page, String sessionID, ListSpecialListener listener) {
        ListSpecialService service = retrofit.create(ListSpecialService.class);
        Call<List<ListSpecialBean>> call = service.getListSpecialList(mod,page,sessionID);
        call.enqueue(new Callback<List<ListSpecialBean>>() {
            @Override
            public void onResponse(Call<List<ListSpecialBean>> call, Response<List<ListSpecialBean>> response) {
                if(response.isSuccessful() && response != null){
                    listener.onResponse(response.body());
                }
                else listener.onFail("on response fail");
            }

            @Override
            public void onFailure(Call<List<ListSpecialBean>> call, Throwable t) {
                listener.onFail(t.toString());
            }
        });
    }
}
